﻿// Author: Nhat Nguyen
// Purpose: this file contain all general function in javascript use for all pages in Website
// Added on 01/17/2013

function getSearchValue(input) {
    var value = input.val();
    if (value == "")
        return null;
    return value;
}

function getDictionaryValue(dic, key) {
    var rs = null;
    $.each(dic, function (i) {
        if (dic[i].name == key)
            rs = dic[i].value;
    });
    return rs;
}
function checkMaxLen(txt, maxLen) {
    if (txt.value.length > (maxLen - 1)) {
        var cont = txt.value;
        txt.value = cont.substring(0, (maxLen - 1));
        return false;

    }
}
// Prevent XSS
function validateXSS(oSrc, args) {
    var _text = args.Value;
    var regex1 = /(<([^>]+)>)/ig; // html tag
    var regex2 = /<!/ig; // <!

    var ischeck = !(regex2.test(_text)) && !(regex1.test(_text));
    args.IsValid = ischeck;

}